﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace JV.MVVM {
    public class BindingEditor: UITypeEditor {

        public override UITypeEditorEditStyle GetEditStyle( System.ComponentModel.ITypeDescriptorContext context ) {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue( System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value ) {

            IWindowsFormsEditorService editorService = null;
            if ( provider != null ) {
                editorService = provider.GetService( typeof( IWindowsFormsEditorService ) ) as IWindowsFormsEditorService;
            }

            if ( editorService != null ) {

                var editor = new BindingEditorForm( );
                editor.Bindings = ( string )value;

                if ( editorService.ShowDialog( editor ) == System.Windows.Forms.DialogResult.OK ) {
                    value = editor.Bindings;
                }

            }

            return value;
        }

    }
}
